//
//  CardDetailView.swift
//  swiftUIdemo
//
//  Created by Z.cy on 2025/1/8.
//

import SwiftUI

struct CardDetailView: View {
    @EnvironmentObject var appState: AppTabBarState
    var namespace: Namespace.ID
    var card: UserCard
    var body: some View {
        
        let screen = UIScreen.main.bounds
        ZStack(alignment: .bottom){
            ScrollView(showsIndicators: false){
                UserCardView(userCard: card)
                    .animation(.easeOut(duration: 0.1))
                    .matchedGeometryEffect(id: card.id, in: namespace)
                    .environmentObject(appState)
                    .frame(width: screen.width, height: screen.height*0.7)
                HStack{
                    VStack(alignment: .leading){
                        HStack{
                            Text(card.name)
                                .font(.system(size: 32,weight: .bold))
                            Text("\(card.age)")
                                .font(.system(size: 28,weight: .bold))
                            Spacer()
                        }
                        Text(card.place)
                            .font(.system(size: 18, weight: .light))
                            .foregroundColor(.gray)
                    }
                    .padding([.horizontal, .top], 20)
                    Button {
                        appState.isTabBarHidden = false
                    }
                    label: {
                        Image(systemName: "arrow.up.circle.fill")
                            .font(.system(size: 40))
                            .background(.white)
                            .clipShape(Circle())
                    }
                    .padding(.trailing, 30)
                    .offset(y: -40)
                }
            }
            
        }
       
    }
}

struct CardDetailView_Previews: PreviewProvider {
    @Namespace static var namespace
    static var previews: some View {
        CardDetailView(namespace: namespace, card: .init(name: "Jame", age: 23, place: "New York", zodiac: "Cancer", photos: ["User1"]))
            .environmentObject(AppTabBarState(isTabBarHidden: true))
    }
}

